package com.lms.thread.demo1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-03-03 15:51
 * @Description: ${Description}
 */
public class MyThreadDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<String> threadA = new MyThread("实现Callable接口方式实现多线程");
        FutureTask<String> task = new FutureTask<>(threadA);
        new Thread(task).start();
        System.out.println(task.get());
    }
}

class MyThread implements Callable<String> {
    private String title;

    public MyThread(String title) {
        this.title = title;
    }

    @Override
    public String call() throws Exception {
        for (int i = 1; i <= 5; i++) {
            System.out.println(title + ":运行---- " + i + " 次");

        }
        return  "返回值";
    }
}